<template>
  <NewModal :title="`上下文调试 - ${modalProps?.debugId || '未知'}`">
    <div class="debug-content">
      <h4>当前模态框上下文信息</h4>
      
      <div class="debug-info">
        <div class="info-item">
          <span class="label">Debug ID:</span>
          <span class="value">{{ modalProps?.debugId }}</span>
        </div>
        
        <div class="info-item">
          <span class="label">Props内容:</span>
          <pre class="props-display">{{ JSON.stringify(modalProps, null, 2) }}</pre>
        </div>
        
        <div class="info-item">
          <span class="label">上下文地址:</span>
          <span class="value">{{ contextAddress }}</span>
        </div>
      </div>

      <div class="actions">
        <button @click="confirmWithData" class="btn btn-primary">
          确认并返回数据
        </button>
        <button @click="cancel" class="btn btn-secondary">
          取消
        </button>
      </div>
    </div>
  </NewModal>
</template>

<script setup>
import { ref } from 'vue';
import { useModalContext } from '../hooks/useModal';
import NewModal from './NewModal.vue';

const { modalProps, confirm, cancel, close } = useModalContext();

// 生成一个唯一的上下文标识符
const contextAddress = ref(
  'ctx_' + Math.random().toString(36).substr(2, 9)
);

const confirmWithData = () => {
  confirm({
    debugId: modalProps?.debugId,
    contextAddress: contextAddress.value,
    timestamp: Date.now(),
    propsReceived: modalProps
  });
};
</script>

<style scoped>
.debug-content {
  padding: 20px;
  min-width: 400px;
}

.debug-info {
  margin-bottom: 20px;
}

.info-item {
  margin-bottom: 12px;
}

.label {
  font-weight: bold;
  color: #333;
  display: block;
  margin-bottom: 4px;
}

.value {
  color: #666;
  font-family: monospace;
}

.props-display {
  background: #f5f5f5;
  padding: 10px;
  border-radius: 4px;
  font-size: 12px;
  max-height: 200px;
  overflow-y: auto;
  margin: 0;
}

.actions {
  display: flex;
  gap: 8px;
}

.btn {
  padding: 8px 16px;
  border: 1px solid;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
}

.btn-primary {
  background: #1890ff;
  border-color: #1890ff;
  color: white;
}

.btn-secondary {
  background: white;
  border-color: #d9d9d9;
  color: #333;
}
</style>